import {
  delVerifySite,
  getOwner,
  getSite,
  verify,
  verifyDetail,
  verifyDetailMe,
  verifySite,
  verifyStatu
} from "../../api/verify"
import {getToken} from "../../utils/auth"

const getDefaultState = () => {
  return {
    token: getToken(),
    name: '',
    avatar: ''
  }
}

const state = getDefaultState()

const mutations = {
  RESET_STATE: (state) => {
    Object.assign(state, getDefaultState())
  },
  SET_TOKEN: (state, token) => {
    state.token = token
  },
  SET_NAME: (state, name) => {
    state.name = name
  },
  SET_AVATAR: (state, avatar) => {
    state.avatar = avatar
  }
}

const actions = {
  // 获取概况整体数据
  verify({ commit },data1) {
    return new Promise((resolve, reject) => {
      verify(data1).then(response => {
        const { data } = response

        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  verifyStatu({ commit },data1) {
    return new Promise((resolve, reject) => {
      verifyStatu(data1).then(response => {
        // const { data } = response

        resolve(response)
      }).catch(error => {
        reject(error)
      })
    })
  },
  verifyDetail({ commit },data1) {
    return new Promise((resolve, reject) => {
      verifyDetail(data1).then(response => {
        const { data } = response

        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  verifyDetailMe({ commit },data1) {
    return new Promise((resolve, reject) => {
      verifyDetailMe(data1).then(response => {
        const { data } = response

        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  verifySite({ commit },data1) {
    return new Promise((resolve, reject) => {
      verifySite(data1).then(response => {
        const { data } = response

        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  delVerifySite({ commit },data1) {
    return new Promise((resolve, reject) => {
      delVerifySite(data1).then(response => {
        const { data } = response

        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  getOwner({ commit },data1) {
    return new Promise((resolve, reject) => {
      getOwner(data1).then(response => {
        const { data } = response

        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  getSite({ commit },data1) {
    return new Promise((resolve, reject) => {
      getSite(data1).then(response => {
        const { data } = response

        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

